<template>
	<view class="content">
		<view class="example">
			<overhaul-step :bidding="isBidding" :active="active" v-if="type == 0" />
			<view class="buttn" v-if="type == 0">
				<view class="choose-box">
					<view style="color: #267DFF; font-size: 32rpx;">指派给:</view>
					<picker @change="teamPickerChange" :value="teamIndex" :range="teams" range-key="name">
						<view>{{ teams[teamIndex].name }}</view>
					</picker>
				</view>
				<button type="primary" @click="submitData">提交</button>
			</view>
		</view>
		<view class="criter_bt">
			<view class="line"></view>
			<text>报价结果</text>
		</view>

		<view class="list-item" v-for="(item, i) in biddingList" :key="i">
			<view class="item-top">
				<view class="top-name" v-if="item.status != 2">
					{{ item.team_name }}:{{ item.monitor_name }}
				</view>
				<view class="top-name-suc" v-if="item.status == 2">
					{{ item.team_name }}:{{ item.monitor_name }}(竞价成功)
				</view>
				<view class="top-date">
					{{ item.create_date }}
				</view>
			</view>
			<view class="item-bottom">
				<view class="bottom-cont">
					<view class="bottom-value">{{ item.maintain_hours }}小时</view>
					<view class="bottom-desc">工时</view>
				</view>
				<view class="bottom-cont">
					<view class="bottom-value">{{ item.maintain_quote }}元</view>
					<view class="bottom-desc">维修费</view>
				</view>
				<view class="bottom-cont">
					<view class="bottom-value">{{ item.begin_date }}</view>
					<view class="bottom-desc">开始时间</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
import OverhaulStep from '@/components/selfs/OverhaulStep.vue'
import { getFormatDateTime } from '@/utils/date-util.js'
import { FILE_URL, saveBiddingInfo, queryBiddingTeamList, saveConfirmTeam } from '@/api/maintenance/selfs.js'
export default {
	components: {
		OverhaulStep
	},
	data () {
		return {
			isBidding: true,
			active: 1,
			type: 0,
			userName: '',
			userId: '',
			deptName: '',
			deptId: '',
			overhaul_id: '',
			now: '',
			fileUrl: FILE_URL,
			biddingList: [],
			checkedTeam: '请选择接收任务班组>',
			teamIndex: 0,
			teams: [{ name: '请选择接收任务班组' }]
		}
	},
	methods: {

		// 查询竞价信息
		fetchBiddingData () {
			let params = { overhaul_id: this.overhaul_id }
			queryBiddingTeamList(params).then(res => {
				this.biddingList = res.datas
				for (let i = 0; i < this.biddingList.length; i++) {
					if (this.biddingList[i].bidding_id) {
						this.teams.push({
							name: this.biddingList[i].team_name,
							bidding_id: this.biddingList[i].bidding_id,
							monitor_user: this.biddingList[i].monitor_user
						})
					}
				}
			})
		},
		teamPickerChange (e) {
			this.teamIndex = e.detail.value
		},

		submitData () {
			if (this.teamIndex == 0) {
				uni.showToast({
					title: '请选择接收任务班组',
					icon: 'none'
				})
				return
			}

			let params = {
				overhaul_id: this.overhaul_id, user_id: this.userId,
				bidding_id: this.teams[this.teamIndex].bidding_id,
				monitor_user: this.teams[this.teamIndex].monitor_user
			}
			uni.showLoading({
				title: '正在提交'
			})
			saveConfirmTeam(params).then(res => {
				uni.$emit('assign_refresh')
				uni.showToast({
					title: '提交成功',
					icon: 'success',
					duration: 1500
				})
				setTimeout(function () {
					uni.navigateBack({
					})
				}, 500)
			})
		}
	},
	onLoad: function (e) {
		this.type = e.type
		this.userName = e.userName
		this.userId = e.userId
		this.deptName = e.deptName
		this.deptId = e.deptId
		this.overhaul_id = e.overhaul_id
		if (this.overhaul_id) {
			this.fetchBiddingData()
		}
		this.now = getFormatDateTime()
		this.begin_date = getFormatDateTime()
	}
}
</script>

<style>
page {
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	background-color: #fff
}

view {
	font-size: 28upx;
	line-height: inherit
}

.content {
	width: 100%;
	margin: 0 auto 150upx;
}

.example {
	width: 91%;
	margin: 20upx auto 20upx;
	padding: 0 30upx 0upx
}

.example-body {
	padding: 0 40upx
}

.buttn {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 5;
		padding: 20rpx;
		display: flex;
		justify-content: center;
		background-color: #FFF;
		
	}

	.buttn button {
		font-size: 30upx;
		background: #267dff;
		border-radius: 0;
		flex: 1;
		border-radius: 8rpx;
	}

.criter_bt {
	padding: 0 10px;
	height: 50px;
	background-color: #f7f7f7;
	font-weight: normal;
	display: flex;
	align-items: center;
	flex-direction: row;
}

.line {
	width: 8upx;
	height: 30upx;
	background: #267DFF;
	border-radius: 10upx;
	display: inline-block;
	vertical-align: middle;
}

.criter_bt text {
	padding-left: 10upx;
	vertical-align: middle;
	font-size: 32upx;
	color: #333333;
}

.list-item {
	border-bottom: 1upx solid #f4f4f4;
	padding: 20rpx;
}

.item-top {
	display: flex;
	justify-content: space-between;
}

.item-bottom {
	display: flex;
	justify-content: space-between;
	margin-top: 20rpx;
}

.bottom-cont {
	text-align: center;
	width: 33%;
}

.top-name {
	font-size: 36rpx;
}

.top-name-suc {
	font-size: 36rpx;
	color: #00CF00;
}

.top-date {
	font-size: 28rpx;
	color: #999999;
}

.bottom-desc {
	font-size: 28rpx;
	color: #999999;
}

.bottom-value {
	color: #058CF5;
	font-size: 34rpx;
	height: 90rpx;
}

.choose-box {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 20rpx;
	border: #267DFF solid 1rpx;
	background: #fff;
}
</style>
